package com.lzy.pattern.iterator.userdefined;

import java.util.List;

/**
 * @ClassName: StudentIteratorImpl
 * @Description: 具体迭代器（Concretelterator）角色：实现抽象迭代器接口中所定义的方法，完成对聚合对象的遍历，记录遍历的当前位置。
 * @Author: LiuZy
 * @Date: 2022/5/1 19:34
 * @Version: 1.0
 */
public class StudentIteratorImpl implements StudentIterator {

    private List<Student> list;
    private Integer position = 0;

    @Override
    public boolean hasNext() {
        return position < list.size();
    }

    @Override
    public Student next() {
        Student student = list.get(position);
        position++;
        return student;
    }

    public StudentIteratorImpl(List<Student> studentList){
        this.list = studentList;
    }
}